<template>
  <el-container>
    <el-menu :default-active="this.$router.path" router class="el-menu-vertical-demo" @open="handleOpen"
      @close="handleClose" :collapse="isCollapse" background-color="#1f4e5f" text-color="#fff" active-text-color="#00fff5"
      :collapse-transition="true" style="text-align:left;" :unique-opened="true">
      <!-- logo -->
      <div class="logo" style="width:200px">
        <img src="@/assets/logo-mini.png" width="60px" style="box-sizing:border-box;padding:10px;" alt />
        <h1 v-show="!isCollapse">宠物家园</h1>
      </div>
      <el-submenu index="/home/businessList">
        <template slot="title">
          <i class="el-icon-s-shop"></i>
          <span slot="title">商家管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="/home/businessList">
            <template slot="title">
              <i class="el-icon-folder-add"></i>
              <span slot="title">商家列表</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/home/businessAdd">
            <template slot="title">
              <i class="el-icon-document-copy"></i>
              <span slot="title">新增商家</span>
            </template>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="/home/usersList">
        <template slot="title">
          <i class="el-icon-user"></i>
          <span slot="title">用户管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="/home/usersList">
            <template slot="title">
              <i class="el-icon-folder-add"></i>
              <span slot="title">用户列表</span>
            </template>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="/home/ordersList">
        <template slot="title">
          <i class="el-icon-shopping-cart-full"></i>
          <span slot="title">订单管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="/home/ordersList">
            <template slot="title">
              <i class="el-icon-folder-add"></i>
              <span slot="title">全部订单</span>
            </template>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="/home/dairyList">
        <template slot="title">
          <i class="el-icon-notebook-2"></i>
          <span slot="title">日志管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="/home/dairyList">
            <template slot="title">
              <i class="el-icon-folder-add"></i>
              <span slot="title">日志列表</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/home/dairyAdd">
            <template slot="title">
              <i class="el-icon-document-copy"></i>
              <span slot="title">新增日志</span>
            </template>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
    <!-- </el-main> -->
    <el-container>
      <el-header>
        <el-row type="flex" justify="space-between">
          <el-col :span="1">
            <!-- 左侧按钮：控制Menu菜单的收缩 -->
            <div class="grid-content bg-purple">
              <i :class="changeName" @click="isCollapse = !isCollapse"></i>
            </div>
          </el-col>
          <el-col :span="4">
            <div class="grid-content bg-purple-light">
              <!-- 头像 -->
              <el-avatar :src="circleUrl"></el-avatar>
              <!-- 名字 -->
              <span>&nbsp;&nbsp;{{ loginAdmin }}&nbsp;&nbsp;</span>
              <!-- 按钮 -->
              <el-button type="danger" round icon="el-icon-switch-button" size="mini" @click="logout">退出</el-button>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
      <el-footer>技术支持：王浩</el-footer>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      circleUrl:
        "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
      isCollapse: false, // 控制左侧菜单展开和收缩
      logoWidth: '180px',
      changeName: "el-icon-s-fold"
    };
  },
  watch: {
    isCollapse(value) {
      if (value) {
        this.logoWidth = "60px";
        this.changeName = "el-icon-s-unfold";
      } else {
        this.logoWidth = "180px";
        this.changeName = "el-icon-s-fold";
      }
    }
  },
  computed: {
    loginAdmin() {
      if (sessionStorage.getItem("admin")) {
        let admin = sessionStorage.getItem("admin");
        admin = JSON.parse(admin);
        return admin.admin;
      }
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    logout() {
      sessionStorage.clear()
      this.$router.replace('/login')
    }
  }
};
</script>

<style scoped>
.el-container {
  width: auto;
  height: 100%;
}

.el-header,
.el-footer {
  height: 60px;
  background-color: #1891ac;
  color: #ffffff;
  text-align: center;
  line-height: 60px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body>.el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-submenu i {
  color: #ffffff !important;
}


.bg-purple i {
  margin-top: 15px;
  font-size: 28px;
  cursor: pointer;
}

.bg-purple-light {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.logo {
  display: flex;
  color: #ffff;
  align-items: center;
}
</style>